var util = require('../../utils/util.js');
var WxParse = require('../../wxParse/wxParse.js');
var qcloud = require('../../vendor/wafer2-client-sdk/index')
var app = getApp();
Page({
  data: {
    status:"0",
    orderId: 0,
    iteminfo:{},
    orderinfo:{},
    tag:"",
    url:"",
    resumeurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailResume.page",
    interviewurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailInterview.page",
    salaryurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailSalary.page",
    planurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailPlan.page",
    leaveurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailLeave.page",
  },

  onLoad: function (options) {
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    console.log("pay success proId=" + options.proId);
    console.log("pay success ordercode" + options.ordercode);
    //已选择的咨询项目
    var itemid = options.proId;

    util.post(app.api.getIdByOrdercode, { ordercode: options.ordercode }, function (res) {
     console.log(res.data)
      that.setData({
        orderinfo: res.data
      });
    });
    
    that.setData({
      status: options.status,
      orderId:that.data.orderinfo.id
    });
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  perfectTap:function(e){
    var that = this;
    console.log("pay success orderId=" + that.data.orderinfo.id);
    wx.navigateTo({
      url: '/pages/my-ordetail/my-ordetail?orderId=' + that.data.orderinfo.id,
    })
  },

   payOrder: function (e) {
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];   //当前页面
    var prevPage = pages[pages.length - 2];  //上一个页面
    wx.navigateBack({
      delta:2
    })
  },
  backhomeTap: function (e) {
    //2019-5-5 upd
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];   //当前页面
    var prevPage = pages[pages.length - 2];  //上一个页面
    if(prevPage.route ==="pages/hunter-order/hunter-order"){
      if(Number(this.data.status)===0){
        wx.navigateBack({
            delta: 2
          })
      }else{
        wx.switchTab({
          url:'/pages/index/index'
        })
      }
    }else{
      wx.navigateBack({
        delta: 3
      })
    }
  },
  gocompleteTap: function () {
    var that = this;
    var orderId = that.data.orderinfo.id; // 当前id
    var tag = that.data.orderinfo.tag;
    console.log("orderId:" + orderId + "  tag:" + tag)
    if (tag.indexOf("简历修改") >= 0) {
      console.log("pay success url=" + that.data.resumeurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.resumeurl)
      })
    } else if (tag.indexOf("面试辅导") >= 0) {
      console.log("pay success url=" + that.data.interviewurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.interviewurl)
      })
    } else if (tag.indexOf("薪酬分析") >= 0) {
      console.log("pay success url=" + that.data.salaryurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.salaryurl)
      })
    } else if (tag.indexOf("职业规划") >= 0) {
      console.log("pay success url=" + that.data.planurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.planurl)
      })
    } else if (tag.indexOf("离职咨询") >= 0) {
      console.log("pay success url=" + that.data.leaveurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.leaveurl)
      })
    }
  }
})